package com.example.mybatisplus.controller;

import com.example.mybatisplus.des.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author longdeng
 * @Date 2020/9/17 0017 23:30
 */
@Controller
@RequestMapping("api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("getUsers")
    @ResponseBody
    public Object getUsers() {
        Map<String, Object> map = new HashMap<>();
        List<User> userList = userService.getUsers(map);
        return userList;
    }


    /**
     * 批量添加用户
     *
     * @return
     */
    @RequestMapping("addUsers")
    @ResponseBody
    public Object addUsers() {
        List<User> userList = userService.addUsers();
        return userList;
    }

    /**
     * 批量添加用户 - 单个插入<br>
     * 和上面的<span style='color:red'>addUsers</span>做一个效率测试
     *
     * @return
     */
    @RequestMapping("addUserBySingle")
    @ResponseBody
    public Object addUserBySingle() {
        List<User> userList = userService.addUserBySingle();
        return userList;
    }

    /**
     * 通过条件信息查询用户信息<br>
     * 和上面的<span style='color:red'>addUsers</span>做一个效率测试
     *
     * @return
     */
    @RequestMapping("getUsersByCon")
    @ResponseBody
    public Object getUsersByCon(@RequestParam Map<String, Object> map) {
        List<User> userList = userService.getUsersByCon(map);
        return userList;
    }

}
